package logic

import (
	"context"
	"month_zg6/rpc/models/mysql"

	"month_zg6/rpc/goods"
	"month_zg6/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WhereLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWhereLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WhereLogic {
	return &WhereLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *WhereLogic) Where(in *goods.WhereGoodsRequest) (*goods.WhereGoodsResponse, error) {
	var good mysql.Goods
	err := mysql.DB.Model(&mysql.Goods{}).Where("goods_name = ?", in.GoodsName).First(&good).Error
	if err != nil {
		return nil, err
	}
	return &goods.WhereGoodsResponse{
		ID:             int64(good.ID),
		GoodsName:      good.GoodsName,
		GoodsInventory: int64(good.GoodsInventory),
		GoodsViews:     good.GoodsViews,
	}, nil
}
